// com.example.myproject.mapper.UserMoneyMapper.java
package com.example.myproject.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.myproject.model.UserMoney;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMoneyMapper extends BaseMapper<UserMoney> {
    @Select("SELECT * FROM user_money WHERE user_id = #{userId}")
    UserMoney selectByUserId(@Param("userId") Long userId);

    @Update("UPDATE user_money SET point = point + #{amount} WHERE user_id = #{userId}")
    int addPoints(@Param("userId") Long userId, @Param("amount") double amount);

    @Update("UPDATE user_money SET magicvalue = magicvalue + #{amount} WHERE user_id = #{userId}")
    int addMagicvalue(@Param("userId") Long userId, @Param("amount") double amount);

    @Update("UPDATE user_money " +
            "SET point = point + #{point}, ticket = ticket + #{ticket}, magicvalue = magicvalue + #{magicvalue} " +
            "WHERE user_id = #{userId}")
    int addRewards(@Param("userId") Long userId,
                   @Param("point") double point,
                   @Param("ticket") double ticket,
                   @Param("magicvalue") double magicvalue);

    @Insert("INSERT INTO user_money (user_id, point, ticket, magicvalue) VALUES (#{userId}, #{point}, #{ticket}, #{magicvalue})")
    int insert(UserMoney userMoney);
}